.mr-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  box-sizing: border-box;
  transition: all 0.3s ease;

  // 默认添加底部间距，让组件更美观
  padding-bottom: 8px;

  // 固定定位模式
  &--fixed {
    position: fixed;
  }

  // 安全区域适配
  &--safe-area {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);

    // 兼容旧版本iOS
    padding-top: constant(safe-area-inset-top);
    padding-bottom: constant(safe-area-inset-bottom);
  }

  // 显示底部边框
  &--show-border {
    border-bottom: 1px solid #f0f0f0;
  }

  // 返回按钮
  &__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: transform 0.2s ease;
    margin-left: 8px;
    background: none;
    border: none;
    padding: 0;

    // 点击时轻微缩放反馈，但无背景色
    &:active {
      transform: scale(0.95);
    }

    // 完全移除所有focus样式
    &:focus,
    &:focus-visible,
    &:focus-within {
      outline: none;
      box-shadow: none;
      background: none;
    }

    // 确保hover时也无背景
    &:hover {
      background: none;
    }
  }

  // 标题内容区域
  &__content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    overflow: hidden;
  }

  // 标题文本
  &__text {
    margin: 0;
    padding: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;

    // 确保文字垂直居中
    display: flex;
    align-items: center;
    justify-content: center;
  }

  // 右侧占位，保持标题居中
  &__placeholder {
    width: 44px;
    height: 44px;
    margin-right: 8px;
  }
}

// 暗黑模式支持
@media (prefers-color-scheme: dark) {
  .mr-title {
    &--show-border {
      border-bottom-color: #333;
    }

    // 暗黑模式下也确保没有背景色
    &__back {
      &:hover,
      &:active,
      &:focus,
      &:focus-visible {
        background: none !important;
      }
    }
  }
}

// 不同屏幕尺寸适配
@media screen and (max-width: 375px) {
  .mr-title {
    &__content {
      padding: 0 12px;
    }

    &__text {
      font-size: 16px;
    }
  }
}

@media screen and (min-width: 768px) {
  .mr-title {
    &__content {
      padding: 0 24px;
    }

    &__text {
      font-size: 20px;
    }
  }
}

// 横屏适配
@media screen and (orientation: landscape) and (max-height: 500px) {
  .mr-title {
    height: 36px;

    &__back {
      width: 36px;
      height: 36px;
    }

    &__placeholder {
      width: 36px;
      height: 36px;
    }

    &__text {
      font-size: 16px;
    }
  }
}

// 高DPI屏幕优化
@media screen and (-webkit-min-device-pixel-ratio: 2) {
  .mr-title {
    border-bottom-width: 0.5px;
  }
}

// 特殊的iPhone X系列适配
@supports (padding: max(0px)) {
  .mr-title--safe-area {
    padding-top: max(env(safe-area-inset-top), 20px);
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
  }
}

// 无障碍功能增强
@media (prefers-reduced-motion: reduce) {
  .mr-title {
    transition: none;

    &__back {
      transition: none;

      &:active {
        transform: none;
      }
    }
  }
}

// 高对比度模式
@media (prefers-contrast: high) {
  .mr-title {
    border-bottom-width: 2px;
    border-bottom-color: currentColor;
  }
}
