.referral-story-promo {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  grid-template-areas: "copy art" "action art";
  align-items: center;
  gap: 22px 32px;
  overflow: hidden;
  padding: 28px 36px;
  border-radius: 28px;
  background: linear-gradient(115deg, #1e54b7, #2c67ce);
  color: #f5f8ff;
}
.referral-story-promo-copy {
  grid-area: copy;
  position: relative;
  z-index: 1;
}
.referral-story-eyebrow {
  margin: 0 0 12px;
  color: #f5f8ff;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}
.referral-story-promo .referral-story-promo-title {
  margin: 0;
  color: #f5f8ff;
  font-size: 36px;
  line-height: 1.06;
  letter-spacing: -1.1px;
  font-weight: 700;
}
.referral-story-promo-description {
  max-width: 300px;
  margin: 14px 0 0;
  color: #f5f8ff;
  font-size: 14px;
  line-height: 21px;
}
.referral-story-promo-art {
  grid-area: art;
  position: relative;
  width: 144px;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  align-self: center;
  pointer-events: none;
}
.referral-story-promo-orbit {
  position: absolute;
  z-index: -1;
  inset: -56px;
  border: 1px solid rgb(245 248 255 / 0.17);
  border-radius: 50%;
  transform: rotate(20deg);
  box-shadow:
    0 0 0 34px rgb(245 248 255 / 0.05),
    0 0 0 68px rgb(245 248 255 / 0.04);
}
.referral-story-promo-back,
.referral-story-promo-image {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 13px;
}
.referral-story-promo-back {
  background: #8bb4f5;
  transform: rotate(-9deg) translate(-10px, 2px);
}
.referral-story-promo-image {
  transform: rotate(9deg) translate(4px, -2px);
  box-shadow: 0 12px 24px rgb(8 39 100 / 0.22);
}
.referral-story-trigger {
  grid-area: action;
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  justify-self: start;
  min-height: 48px;
  max-width: 100%;
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  background: #f5f8ff;
  color: #17448f;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 22px;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    box-shadow 150ms ease;
}
.referral-story-trigger:hover {
  background: #e3edff;
  box-shadow: 0 4px 16px rgb(8 39 100 / 0.15);
}
.referral-story-trigger:active {
  background: #d5e4ff;
}
.referral-story-trigger:focus-visible {
  outline: 2px solid #f5f8ff;
  outline-offset: 4px;
}
.referral-story-trigger:disabled,
.referral-story-share:disabled {
  opacity: 0.45;
  cursor: default;
}
.referral-story-trigger svg {
  flex-shrink: 0;
}
.referral-story-share:focus-visible {
  outline: 2px solid rgb(var(--color-accent-500));
  outline-offset: 3px;
}
@media (max-width: 600px) {
  .referral-story-promo {
    grid-template-columns: minmax(0, 1fr) 94px;
    grid-template-areas: "copy art" "action action";
    gap: 22px 16px;
    padding: 24px;
    border-radius: 26px;
  }
  .referral-story-promo .referral-story-promo-title {
    font-size: 29px;
    letter-spacing: -0.9px;
  }
  .referral-story-promo-description {
    font-size: 13px;
    line-height: 19px;
    margin-top: 12px;
  }
  .referral-story-eyebrow {
    font-size: 10px;
    letter-spacing: 1.3px;
    margin-bottom: 10px;
  }
  .referral-story-promo-art {
    width: 94px;
  }
  .referral-story-promo-image,
  .referral-story-promo-back {
    border-radius: 10px;
  }
  .referral-story-trigger {
    justify-self: stretch;
  }
}
@media (max-width: 359px) {
  .referral-story-promo {
    padding: 20px;
    grid-template-columns: minmax(0, 1fr) 74px;
    gap: 20px 12px;
  }
  .referral-story-promo .referral-story-promo-title {
    font-size: 26px;
  }
  .referral-story-promo-art {
    width: 74px;
  }
  .referral-story-trigger {
    font-size: 14px;
    padding-inline: 14px;
  }
}
.dialog-surface.referral-story-dialog {
  overflow: clip;
}
.referral-story-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
}
.referral-story-dialog .dialog-body {
  display: block;
  min-width: 0;
  overflow-x: hidden;
  scrollbar-width: thin;
}
.referral-story-hint {
  margin: 6px 24px 24px 0;
  line-height: 1.5;
}
.referral-story-layout {
  display: grid;
  grid-template-columns: minmax(0, 396px) minmax(240px, 1fr);
  gap: 28px;
  align-items: center;
}
.referral-story-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 18px;
  border-radius: 22px;
  background: #e8eef8;
}
.referral-story-stage.is-blue {
  background: #e1eafa;
}
.referral-story-stage.is-graphite {
  background: #dce1e9;
}
.dark .referral-story-stage {
  background: #202b3b;
}
.dark .referral-story-stage.is-graphite {
  background: #303844;
}
.referral-story-preview {
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(14 23 32 / 0.16);
}
.referral-story-preview img {
  display: block;
  width: 100%;
  height: auto;
}
.referral-story-editor {
  min-width: 0;
}
.referral-story-variants {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.referral-story-variants legend {
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 600;
  color: rgb(var(--color-dark-100));
}
.referral-story-variant-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.referral-story-variant {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 8px;
  min-width: 0;
  border: 2px solid transparent;
  border-radius: 14px;
  background: rgb(var(--color-dark-400) / 0.08);
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background-color 150ms ease;
}
.referral-story-variant:hover {
  background: rgb(var(--color-dark-400) / 0.14);
}
.referral-story-variant.is-selected {
  border-color: #3374df;
  background: rgb(var(--color-accent-500) / 0.09);
}
.referral-story-variant:has(input:focus-visible) {
  outline: 2px solid #3374df;
  outline-offset: -4px;
}
.referral-story-variant input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.referral-story-variant img {
  display: block;
  width: 42px;
  height: auto;
  border-radius: 4px;
}
.referral-story-variant-name {
  font-size: 12px;
  line-height: 18px;
  color: rgb(var(--color-dark-200));
}
.referral-story-variant.is-selected .referral-story-variant-name {
  font-weight: 600;
}
.referral-story-variant-check {
  position: absolute;
  top: 5px;
  right: 5px;
  color: #3374df;
}
.referral-story-link-hint {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 22px 0;
  color: rgb(var(--color-dark-300));
  font-size: 13px;
  line-height: 20px;
}
.referral-story-link-hint svg {
  flex: 0 0 20px;
  margin-top: 1px;
}
.referral-story-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.referral-story-actions .btn-primary,
.referral-story-actions .btn-secondary {
  text-align: center;
  justify-content: center;
  min-height: 46px;
  padding: 12px;
  font-size: 15px;
}
.referral-story-actions .btn-primary:disabled {
  opacity: 0.65;
  cursor: default;
}
.referral-story-status {
  font-size: 13px;
  line-height: 1.5;
  color: rgb(var(--color-dark-300));
}
.referral-story-status:empty {
  display: none;
}
.referral-story-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px;
  border: 0;
  border-radius: 12px;
  color: rgb(var(--color-dark-200));
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  cursor: pointer;
}
.referral-story-share:hover {
  background: rgb(var(--color-dark-400) / 0.1);
}
@media (max-width: 768px) {
  .referral-story-dialog {
    width: 100%;
    max-height: calc(100dvh - max(env(safe-area-inset-top, 0px), var(--dialog-safe-top, 0px)) - 12px);
  }
}
@media (max-width: 768px) {
  .referral-story-hint {
    margin-bottom: 18px;
  }
  .referral-story-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }
  .referral-story-stage {
    padding: 14px;
    border-radius: 18px;
  }
  .referral-story-variant {
    flex-direction: row;
    gap: 4px;
    justify-content: center;
    padding: 10px 3px;
    min-height: 48px;
    border-radius: 12px;
  }
  .referral-story-variant img {
    width: 16px;
    border-radius: 2px;
  }
  .referral-story-variant-check {
    top: -4px;
    right: 0;
    width: 16px;
    height: 16px;
  }
  .referral-story-link-hint {
    margin: 16px 0;
  }
}

/* Reserve the real controls height, then fit the complete artwork in the rest. */
@media (max-width: 768px) {
  .referral-story-dialog {
    height: calc(100dvh - max(env(safe-area-inset-top, 0px), var(--dialog-safe-top, 0px)) - 12px);
  }
  .referral-story-dialog .dialog-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0;
  }
  .referral-story-dialog .dialog-body > h2,
  .referral-story-hint {
    flex-shrink: 0;
  }
  .referral-story-hint {
    margin-bottom: 12px;
  }
  .referral-story-layout {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    gap: 14px;
  }
  .referral-story-stage {
    container-type: size;
    flex: 1;
    min-height: 100px;
    padding: 12px;
  }
  .referral-story-preview {
    width: min(360px, 100cqw, calc(100cqh * 9 / 16));
    flex-shrink: 0;
  }
  .referral-story-editor {
    flex-shrink: 0;
  }
  .referral-story-link-hint {
    margin: 12px 0;
  }
}

@media (min-width: 769px) and (max-height: 850px) {
  .referral-story-dialog {
    height: calc(100dvh - 48px);
  }
  .referral-story-dialog .dialog-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0;
  }
  .referral-story-dialog .dialog-body > h2,
  .referral-story-hint {
    flex-shrink: 0;
  }
  .referral-story-layout {
    flex: 1;
    min-height: 0;
    margin-top: 12px;
  }
  .referral-story-stage {
    container-type: size;
    align-self: stretch;
    min-height: 100px;
  }
  .referral-story-preview {
    width: min(360px, 100cqw, calc(100cqh * 9 / 16));
  }
}
@media (max-width: 768px) and (max-height: 760px), (max-height: 650px) {
  .referral-story-hint {
    display: none;
  }
  .referral-story-layout {
    margin-top: 12px;
    gap: 12px;
  }
  .referral-story-variants legend {
    margin-bottom: 8px;
  }
  .referral-story-variant {
    flex-direction: row;
    justify-content: center;
    gap: 4px;
    min-height: 44px;
    padding: 8px 3px;
  }
  .referral-story-variant img {
    width: 16px;
  }
  .referral-story-variant-check {
    top: -4px;
    right: 0;
    width: 16px;
    height: 16px;
  }
  .referral-story-link-hint {
    margin: 10px 0;
  }
  .referral-story-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .referral-story-actions .btn-primary,
  .referral-story-actions .btn-secondary {
    font-size: 13px;
    padding: 10px 8px;
  }
  .referral-story-actions > .referral-story-share,
  .referral-story-status {
    grid-column: 1 / -1;
  }
}

.referral-story-destination-hint {
  margin: 20px 0 12px;
  font-size: 13px;
  line-height: 20px;
  color: rgb(var(--color-dark-300));
}
.referral-story-destinations { display: grid; gap: 10px; }
.referral-story-destination {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: 1px solid rgb(var(--color-dark-400) / .25);
  border-radius: 14px;
  background: rgb(var(--color-dark-400) / .06);
  color: rgb(var(--color-dark-100));
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.referral-story-destination svg { flex-shrink: 0; }
.referral-story-destination > span:last-child { margin-left: auto; font-size: 19px; }
.referral-story-destination.is-telegram {
  background: rgb(var(--color-accent-500));
  color: #f5f8ff;
  border-color: transparent;
}
.referral-story-destination.is-instagram {
  background: #f0f2f5;
  color: #202d42;
  border-color: #dce1e8;
}
.dark .referral-story-destination.is-instagram {
  background: #202c38;
  color: #f5f8ff;
  border-color: #3a4857;
}
.referral-story-instagram-glyph {
  display: block;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
}
.referral-story-destination:hover { filter: brightness(.96); }
.referral-story-destination:focus-visible,
.referral-story-back:focus-visible,
.referral-story-guide a:focus-visible {
  outline: 2px solid rgb(var(--color-accent-500));
  outline-offset: 3px;
}
.referral-story-destination:disabled { opacity: .45; cursor: default; }
.referral-story-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: rgb(var(--color-dark-300));
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.referral-story-guide-title {
  margin: 8px 0 18px;
  font-size: 21px;
  line-height: 26px;
  font-weight: 600;
  letter-spacing: -.4px;
  color: rgb(var(--color-dark-100));
  outline: none;
}
.referral-story-steps {
  display: grid;
  gap: 18px;
  counter-reset: story-step;
  list-style: none;
  margin: 0;
  padding: 0;
}
.referral-story-steps > li {
  position: relative;
  display: grid;
  gap: 8px;
  padding-left: 32px;
  min-width: 0;
  counter-increment: story-step;
}
.referral-story-steps > li::before {
  content: counter(story-step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgb(var(--color-accent-500) / .12);
  color: rgb(var(--color-dark-100));
  font-size: 12px;
  font-weight: 600;
}
.referral-story-step-copy strong { font-size: 14px; font-weight: 600; line-height: 21px; color: rgb(var(--color-dark-100)); }
.referral-story-step-copy p { margin: 4px 0 0; font-size: 12px; line-height: 18px; color: rgb(var(--color-dark-300)); }
.referral-story-steps .btn-primary,
.referral-story-steps .btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
  text-align: center;
  font-size: 14px;
}
.referral-story-personal-link {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: rgb(var(--color-dark-300));
  font-size: 12px;
  line-height: 18px;
  user-select: all;
}
.referral-story-guide > .referral-story-share { width: 100%; margin-top: 8px; }
.referral-story-guide .referral-story-status { margin: 8px 0 0; }
.referral-story-dialog.is-guide .referral-story-hint { display: none; }
.referral-story-dialog.is-guide .referral-story-layout { margin-top: 12px; }
@media (max-width: 768px) {
  .referral-story-dialog.is-guide .referral-story-stage { display: none; }
  .referral-story-dialog.is-guide .referral-story-editor { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
  .referral-story-guide-title { margin-top: 4px; }
}
@media (max-height: 650px) {
  .referral-story-steps { gap: 12px; }
  .referral-story-guide-title { margin: 0 0 12px; font-size: 19px; }
}

.referral-story-guide-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.referral-story-guide-heading .referral-story-guide-title { margin-bottom: 0; }
.referral-story-guide-heading > img { flex-shrink: 0; width: 40px; height: auto; border-radius: 5px; }
@media (max-height: 650px) {
  .referral-story-guide-heading { margin-bottom: 12px; }
  .referral-story-guide-heading > img { width: 32px; }
}

.referral-story-save-actions { display: flex; gap: 8px; min-width: 0; }
.referral-story-save-actions > .btn-secondary { flex: 1; min-width: 0; }
.referral-story-image-share {
  display: grid; place-items: center; flex: 0 0 44px; min-height: 44px; padding: 0;
  border: 1px solid rgb(var(--color-dark-400) / .25); border-radius: 12px;
  background: rgb(var(--color-dark-400) / .06); color: rgb(var(--color-dark-100)); cursor: pointer;
}
.referral-story-image-share:disabled { opacity: .45; cursor: default; }
.referral-story-image-share:focus-visible { outline: 2px solid rgb(var(--color-accent-500)); outline-offset: 3px; }

@media (max-height: 650px) {
  .referral-story-destination-hint { margin: 14px 0 10px; }
}
